// @ts-ignore
/* eslint-disable */

import { request, type RequestOptions } from '@/utils/request';

/**
* productDocuments
* @param params
* @returns
*/
export async function productDocuments(params: any, options?: RequestOptions) {
    return request<any>(`productdocument/productdocuments`, {
        method: 'POST',
        data: params,
        ...(options || {}),
    });
}

/**
* all
* @param key:string
* @param productId:string
* @param customerId:string
* @returns
*/
export async function all(key: string, productId?: string, customerId?: string, options?: RequestOptions) {
    return request<any[]>(`productdocument/all`, {
        method: 'GET',
        params: { key, productId, customerId },
        ...(options || {}),
    });
}

/**
* get
* @param id:string
* @returns
*/
export async function get(id: string, options?: RequestOptions) {
    return request<any>(`productdocument/${id}`, {
        method: 'GET',
        ...(options || {}),
    });
}

/**
* edit
* @param data
* @returns
*/
export async function edit(data: any, options?: RequestOptions) {
    return request<boolean>(`productdocument/edit`, {
        method: 'POST',
        data,
        ...(options || {}),
    });
}

/**
* create
* @param data
* @returns
*/
export async function create(data: any, options?: RequestOptions) {
    return request<boolean>(`productdocument/create`, {
        method: 'POST',
        data,
        ...(options || {}),
    });
}

/**
* logicDelete
* @param id:string
* @returns
*/
export async function logicDelete(id: string, options?: RequestOptions) {
    return request<boolean>(`productdocument/${id}/logic-delete`, {
        method: 'POST',
        ...(options || {}),
    });
}

/**
* realDelete
* @param id:string
* @returns
*/
export async function realDelete(id: string, options?: RequestOptions) {
    return request<boolean>(`productdocument/${id}/real-delete`, {
        method: 'POST',
        ...(options || {}),
    });
}

/**
* updateStatus
* @param id:string
* @param status:number
* @returns
*/
export async function updateStatus(id: string, status: number, options?: RequestOptions) {
    return request<boolean>(`productdocument/${id}/update-status`, {
        method: 'POST',
        data: status,
        ...(options || {}),
    });
}

/**
* getQrCode
* @param deviceNo:string
* @returns
*/
export async function getQrCode(deviceNo: string, options?: RequestOptions) {
    // 直接使用 axios 进行文件下载
    const axios = (await import('axios')).default;
    const { baseApiUrl } = await import('@/utils/request');
    const { useUserStore } = await import('@/store/modules/user');
    
    const userStore = useUserStore();
    const token = userStore.token;
    
    const response = await axios.get(`${baseApiUrl}productdocument/QrCode`, {
        params: { deviceNo },
        responseType: 'blob',
        headers: {
            ...(token ? { 'Authorization': `Bearer ${token}` } : {}),
        },
    });
    
    return response.data;
} 